Ext.require([
    'Ext.tree.*',
    'Ext.data.*',
    'Ext.layout.container.HBox',
    'Ext.window.MessageBox'
]);

Ext.define('treeModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name'},
        {name: 'text', mapping: 'name'},
        {name: 'code'},
        {name: 'id'},
        //     {name:'checked'},
        {name: 'url'},
        {name: 'leaf'}
    ]
});

var unitStore = Ext.create('Ext.data.Store', {
    fields: ['abbr', 'name'],
    data: [
        {"abbr": "1", "name": "元"},
        {"abbr": "10000", "name": "万元"},
        {"abbr": "100000000", "name": "亿元"}
    ]
});

function EleStoreEnum(param) {
    //code#value+code1#value1
    var json_store = new Array();
    var keyValues = param.split("+");
    for (var i = 0; i < keyValues.length; i++) {
        var keyValue = keyValues[i];
        var key_value = keyValue.split("#");
        var key = key_value[0];
        var value = key_value[1];
        json_store.push({id: key, code: key, name: key + " " + value});
    }
    var enumStore = Ext.create('Ext.data.Store', {
        fields: ['code', 'name'],
        data: json_store
    });
    return enumStore;
};

function DebtOlapEleStoreTable(table, params) {
    var extraParams = {};
    if (typeof params == 'object') {
        extraParams = params;
    }
    extraParams.table = table;
    var debtStoreDB = new Ext.data.Store({
        autoLoad: true,
        fields: ['code', 'name'],
//        sorters: [{
//            property: 'code',
//            direction: 'asc'
//        }],
        proxy: {
            type: 'ajax',
            url: '/sys-report/getOlapStroreByTable',
            extraParams: extraParams,
            reader: {
                type: 'json',
                root: 'list'
            }
        }
    });
    return debtStoreDB;
};

/*下拉树形式，从后台数据库获取数据*/
function DebtOlapTreeStoreDBTable(table, params, isMul) {
    var extraParams = {};
    if (typeof params == 'object') {
        extraParams = params;
    }
    var debtTreeStoreDB;
    extraParams.table = table;
    if (isMul == 0) {
        debtTreeStoreDB = Ext.create('Ext.data.TreeStore', {
            model: 'treeModel',
            proxy: {
                type: 'ajax',
                method: 'POST',
                url: '/sys-report/getOlapTreeByTable',
                extraParams: extraParams,
                reader: {
                    type: 'json'
                }
            },
            root: {name: '全部'},
            autoLoad: true
        });
    } else {
        debtTreeStoreDB = Ext.create('Ext.data.TreeStore', {
            model: 'treeModel',
            proxy: {
                type: 'ajax',
                method: 'POST',
                url: '/sys-report/getOlapTreeByTable',
                extraParams: extraParams,
                reader: {
                    type: 'json'
                }
            },
            root: {name: '全部', checked: false},
            autoLoad: true
        });
    }

    return debtTreeStoreDB;
};
